import JSEncrypt from "jsencrypt/bin/jsencrypt";

// 密钥对生成 http://web.chacuo.net/netrsakeypair
const publicKey =
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCciQe64u4T8oart9jzQ6t71Ym7WB8QYvm06M6kr6vvVLHOTPTGGk39fUYes5m8NTPnDJR/pd0X8LfN2Qh0I/k23MBvlceneHyxJVXb4NhhkHQ5Iewl4pCg5PRJMEmRiS6P6L7vgQcYXGR2pfrfl57y0OYHmcYFq99RLUrTEfd9AwIDAQAB";
// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(publicKey);
  return encryptor.decrypt(txt);
}
